<?php
declare (strict_types = 1);
namespace app\api\controller;

use think\Request;
use think\Exception;
use think\exception\ValidateException;

use app\api\controller\BaseController;
use service\JsonService as Json;

use app\common\model\{User};
use app\common\validate\{ImgValidate};

class HomeController extends BaseController
{
    /** 
     * 上传图片 
     */
    public function imgUp()
    {
        $data['img'] = request()->file('img');
    
        try{
            validate(ImgValidate::class)->scene('img')->check($data);
        }catch(ValidateException $e){
            return Json::fail($e->getError());
        }
            
        $imgUrl = fileUp($data['img']);
    
        return Json::success('上传成功', ['img_url' => $imgUrl]);
    }
}